package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduTeacherDTO;
import com.zenith.edu.po.vo.EduTeacherVO;
import com.zenith.edu.service.EduTeacherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/teacher")
@Tag(name = "教师管理", description = "教师管理接口")
public class EduTeacherController {
    
    @Autowired
    private EduTeacherService eduTeacherService;
    
    @SecurePostMapping(value = "/createTeacher", roles = "ROLE_ADMIN", permission = "teacher:create")
    @Operation(summary = "创建教师")
    public Result<EduTeacherVO> createTeacher(@RequestBody EduTeacherDTO dto) {
        EduTeacherVO teacherVO = eduTeacherService.createTeacher(dto);
        return Result.success(teacherVO);
    }
    
    @SecurePostMapping(value = "/getTeacherById/{id}", roles = "ROLE_ADMIN", permission = "teacher:read")
    @Operation(summary = "根据ID获取教师详情")
    public Result<EduTeacherVO> getTeacherById(@PathVariable Long id) {
        EduTeacherVO teacherVO = eduTeacherService.getTeacherById(id);
        if (teacherVO == null) {
            return Result.fail("教师不存在");
        }
        return Result.success(teacherVO);
    }
    
    @SecurePostMapping(value = "/updateTeacher", roles = "ROLE_ADMIN", permission = "teacher:update")
    @Operation(summary = "更新教师信息")
    public Result<EduTeacherVO> updateTeacher(@RequestBody EduTeacherDTO dto) {
        EduTeacherVO teacherVO = eduTeacherService.updateTeacher(dto);
        return Result.success(teacherVO);
    }
    
    @SecurePostMapping(value = "/deleteTeacher/{id}", roles = "ROLE_ADMIN", permission = "teacher:delete")
    @Operation(summary = "删除指定教师")
    public Result<Void> deleteTeacher(@PathVariable Long id) {
        boolean result = eduTeacherService.deleteTeacher(id);
        if (!result) {
            return Result.fail("教师删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getTeacherList", roles = "ROLE_ADMIN", permission = "teacher:read")
    @Operation(summary = "获取教师列表")
    public Result<List<EduTeacherVO>> getTeacherList() {
        List<EduTeacherVO> teacherList = eduTeacherService.getTeacherList();
        return Result.success(teacherList);
    }
}